import request from '@/utils/request'

export const authApi = {
  // 登录
  login(data) {
    return request.post('/auth/login', data)
  },
  
  // 登出
  logout() {
    return request.post('/auth/logout')
  },
  
  // 获取用户信息
  getUserInfo() {
    return request.get('/auth/profile')
  },

  // 更新用户资料
  updateProfile(data) {
    return request.put('/auth/profile', data)
  },
  
  // 刷新token
  refreshToken() {
    return request.post('/auth/refresh')
  },
  
  // 修改密码
  changePassword(data) {
    return request.put('/auth/change-password', data)
  },

  // 上传头像
  uploadAvatar(file) {
    const formData = new FormData()
    formData.append('file', file)
    return request.post('/auth/upload-avatar', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 注册
  register(data) {
    return request.post('/auth/register', data)
  },

  // 发送邮箱验证码
  sendEmailCode(email) {
    return request.post('/auth/send-email-code', { email })
  },

  // 验证邮箱验证码
  verifyEmailCode(email, code) {
    return request.post('/auth/verify-email-code', { email, code })
  },

  // 获取图形验证码
  getCaptcha() {
    return request.get('/auth/captcha')
  },

  // 验证图形验证码
  verifyCaptcha(captchaId, code) {
    return request.post('/auth/verify-captcha', { captchaId, code })
  },

  // 忘记密码 - 验证用户信息
  verifyUserInfo(data) {
    return request.post('/auth/forgot-password/verify-user', data)
  },

  // 忘记密码 - 发送重置密码邮箱验证码
  sendResetPasswordEmailCode(data) {
    return request.post('/auth/forgot-password/send-email-code', { email: data.email })
  },

  // 忘记密码 - 重置密码
  resetPassword(data) {
    return request.post('/auth/forgot-password/reset', data)
  }
}
